/* 配额调整列表页
 * @Author: Setsuna
 * @Email: 601890383@qq.com
 * @FilePath: \src\pages\QuotaManage\QuotaAdjust\List.tsx
 * @Date: 2021-08-30 09:31:11
 * @LastEditTime: 2021-09-14 16:49:27
 */
import React, { ReactElement } from 'react'
import {
  BaseListPage,
  columnRenders,
  http,
  IBaseListPageState,
  IBaseListPageProps,
  UdDrawer,
  uaaApp,
  IUdFormItem,
  UdModal,
  UdModalForm,
  UdYearPicker,
  IListQueryParams,
} from '@/lib'
import { Button, Input, message, Radio, Select, Spin, Tooltip, TreeSelect, Upload } from 'antd'
import udMainStore from '@/store/UdMain'
import UdSelect from '@/components/UdFormControls/UdSelect'
import './list.scss'

import IncreaseForm from './component/IncreaseForm'
import DeductForm from './component/DeductForm'
import AdjustForm from './component/AdjustForm'
import CustomerForm from './component/CustomerForm'
import BatchFreeze from './component/BatchFreeze'
import BatchOperation from './component/BatchOperation'
import BatchOperate from './component/BatchOperate'
import FreezeRecord from './FreezeRecord'
import AdjustRecord from './AdjustRecord'
import quotaApis from '@/apis/AboutQuota'
import apis from '@/apis'
import inputApis from '@/apis/StatementOfAccount/index'
import { WrappedFormUtils } from 'antd/lib/form/Form'
import _ from 'lodash'
import LinkDetail from './component/LinkDetail'
import { downBlobFileXlsx } from '@/utils/methods'
const { TreeNode } = TreeSelect
const { Option } = Select

const quota_adjust_freezelog = 'quota_adjust_freezelog'
const quota_adjust_log = 'quota_adjust_log'
const quota_adjust_freezein = 'quota_adjust_freezein'
const quota_adjust_freezein_batch = 'quota_adjust_freezein_batch'
const quota_adjust_unfreeze = 'quota_adjust_unfreeze'
const quota_adjust_unfreeze_batch = 'quota_adjust_unfreeze_batch'
const quota_adjust_export = 'quota_adjust_export'
const quota_adjust_supply = 'quota_adjust_supply'
const quota_adjust_deduct = 'quota_adjust_deduct'
const quota_adjust_adjust = 'quota_adjust_adjust'
const quota_adjust_adjustcustom = 'quota_adjust_adjustcustom'
class List extends BaseListPage<QuotaListProps, QuotaListState> {
  protected useConditionsField = true
  // 隐藏掉头曲二曲
  // public hideArr: any = ['头曲', '二曲', '泸州老窖头曲酒类销售有限公司', '泸州老窖二曲酒类销售有限公司']
  // public brandList = udMainStore.brandList.filter(item => this.hideArr.indexOf(item.title) === -1)
  private modal
  public brandList = udMainStore.brandList
  private FROZEN_STATUS_ENUM: any = {
    0: '未冻结',
    1: '已冻结',
  }
  private spanUI: any = {
    color: '#00c1de',
    fontWeight: 'bold',
    cursor: 'pointer',
    paddingRight: '10px',
    padding: '10px 0',
  }
  constructor(props) {
    super(props)
    this.state = {
      title: '配额调整',
      queryApi: params => {
        return http.post(quotaApis.getQuotaAdjustPage, params)
      },
      method: 'POST',
      rowKey: 'id',
      conditions: [
        {
          label: '品牌公司',
          id: 'brandCode',
          initialValue: this.brandList[0].value,
          render: (
            <UdSelect
              showSearch
              allowClear={false}
              options={this.brandList}
              onChange={value => {
                this.changeBrandCode(value)
              }}
            />
          ),
        },
        {
          label: '片区',
          id: 'belongAreaCode',
          render: () => (
            <TreeSelect showSearch treeNodeFilterProp="title">
              {this.mapTree(this.state.treeDataList)}
            </TreeSelect>
          ),
        },
        {
          label: '配额品项',
          id: 'prodBarcode',
          render: () => <UdSelect showSearch options={this.state.prodBarCodeList} />,
        },
        {
          label: '客户编码',
          id: 'dealerCode',
        },
        { label: '客户名称', id: 'dealerName' },
        {
          label: '计划内冻结状态',
          id: 'frozenStatus',
          render: (
            <Select>
              <Option value={0}>未冻结</Option>
              <Option value={1}>已冻结</Option>
            </Select>
          ),
        },
        {
          label: '计划外冻结状态',
          id: 'frozenStatusWay',
          render: (
            <Select>
              <Option value={0}>未冻结</Option>
              <Option value={1}>已冻结</Option>
            </Select>
          ),
        },
        {
          id: 'stageYear',
          label: '考核年度',
          render: () => <UdYearPicker className={'ext'} />,
        },
        { label: '考核阶段', id: 'stageName' },
      ],
      columns: [
        { title: '序号', dataIndex: 'id', key: 'id', width: 50, render: (text, reoled, index) => index + 1 },
        { title: '客户编码', dataIndex: 'dealerCode', width: '100px' },
        { title: '客户名称', dataIndex: 'dealerName', width: 230 },
        { title: '品牌公司', dataIndex: 'brandName', width: 230 },
        { title: '配额品项', dataIndex: 'prodBarname', width: '160px' },
        { title: '考核年度', dataIndex: 'stageYear', width: '80px' },
        {
          title: '考核阶段',
          dataIndex: 'stageName',
          width: '120px',
          render: (text, record) => {
            return (
              <Tooltip title={record.stageName}>
                <div style={{ width: '120px', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }}>
                  {record.stageName}
                </div>
              </Tooltip>
            )
          },
        },
        { title: '片区', dataIndex: 'belongAreaName', width: '100px' },
        {
          title: '配额有效期',
          dataIndex: 'term',
          width: '160px',
          render: (text, record) => {
            return record.stageBeginTime && record.stageEndTime ? `${record.stageBeginTime}-${record.stageEndTime}` : ''
          },
        },
        // { title: '考核阶段实际配额', dataIndex: 'actualQuota', fixedWidth: '100px' },
             {
          title: '配额订单编号',
          key: 'businessItemNumberTitle',
          dataIndex: 'businessItemNumberTitle',
          align: 'center',
          children: [
            {
              title: '计划内',
              align: 'center',
              dataIndex: 'businessItemNumber',
              key: 'businessItemNumber',
              width: 90,
            },
            {
              title: '计划外',
              align: 'center',
              dataIndex: 'businessItemNumberWay',
              key: 'businessItemNumberWay',
              width: 90,
            },
          ],
        },
        {
          title: '考核阶段实际配额',
          key: 'actualQuotaTitle',
          dataIndex: 'actualQuotaTitle',
          align: 'center',
          children: [
            {
              title: '计划内',
              align: 'center',
              dataIndex: 'actualQuota',
              key: 'actualQuota',
              width: 90,
            },
            {
              title: '计划外',
              align: 'center',
              dataIndex: 'actualQuotaWay',
              key: 'actualQuotaWay',
              width: 90,
            },
          ],
        },
        {
          title: '已执行',
          key: 'usingQuotaTitle',
          dataIndex: 'usingQuotaTitle',
          align: 'center',
          children: [
            {
              title: '计划内',
              align: 'center',
              dataIndex: 'executedQuotaAmount',
              key: 'executedQuotaAmount',
              width: 90,
              render: (text, record) => {
                return record.executedQuotaAmount ? (
                  <span
                    onClick={() => {
                      this.handGolinkOrder(record, 0)
                    }}
                    style={this.spanUI}
                  >
                    {record.executedQuotaAmount}
                  </span>
                ) : (
                  record.executedQuotaAmount
                )
              },
            },
            {
              title: '计划外',
              align: 'center',
              dataIndex: 'executedQuotaAmountWay',
              key: 'executedQuotaAmountWay',
              width: 90,
              render: (text, record) => {
                return record.executedQuotaAmountWay ? (
                  <span
                    onClick={() => {
                      this.handGolinkOrder(record, 1)
                    }}
                    style={this.spanUI}
                  >
                    {record.executedQuotaAmountWay}
                  </span>
                ) : (
                  record.executedQuotaAmountWay
                )
              },
            },
          ],
        },
        {
          title: '执行中',
          key: 'useQuotaTitle',
          dataIndex: 'useQuotaTitle',
          align: 'center',
          children: [
            {
              title: '计划内',
              align: 'center',
              dataIndex: 'inExecutionQuotaAmount',
              key: 'inExecutionQuotaAmount',
              width: 90,
              render: (text, record) => {
                return record.inExecutionQuotaAmount ? (
                  <span
                    onClick={() => {
                      this.handGolinkOrder(record, 0)
                    }}
                    style={this.spanUI}
                  >
                    {record.inExecutionQuotaAmount}
                  </span>
                ) : (
                  record.inExecutionQuotaAmount
                )
              },
            },
            {
              title: '计划外',
              align: 'center',
              dataIndex: 'inExecutionQuotaAmountWay',
              key: 'inExecutionQuotaAmountWay',
              width: 90,
              render: (text, record) => {
                return record.inExecutionQuotaAmountWay ? (
                  <span
                    onClick={() => {
                      this.handGolinkOrder(record, 1)
                    }}
                    style={this.spanUI}
                  >
                    {record.inExecutionQuotaAmountWay}
                  </span>
                ) : (
                  record.inExecutionQuotaAmountWay
                )
              },
            },
          ],
        },
        // { title: '考核阶段剩余配额', dataIndex: 'residualQuota', width: '100px' },
        {
          title: '考核阶段剩余配额',
          key: 'residualQuotaTitle',
          dataIndex: 'residualQuotaTitle',
          align: 'center',
          children: [
            {
              title: '计划内',
              align: 'center',
              dataIndex: 'residualQuota',
              key: 'residualQuota',
              width: 90,
            },
            {
              title: '计划外',
              align: 'center',
              dataIndex: 'residualQuotaWay',
              key: 'residualQuotaWay',
              width: 90,
            },
          ],
        },
        // { title: '年度剩余配额', dataIndex: 'residualQuotaYearSum', width: '90px' },
        {
          title: '年度剩余配额',
          key: 'residualQuotaYearSumTitle',
          dataIndex: 'residualQuotaYearSumTitle',
          align: 'center',
          children: [
            {
              title: '计划内',
              align: 'center',
              dataIndex: 'residualQuotaYearSum',
              key: 'residualQuotaYearSum',
              width: 90,
            },
            {
              title: '计划外',
              align: 'center',
              dataIndex: 'residualQuotaYearSumWay',
              key: 'residualQuotaYearSumWay',
              width: 90,
            },
          ],
        },
        // {
        //   title: '配额有效期',
        //   dataIndex: 'term',
        //   width: '160px',
        //   render: (text, record) => {
        //     return record.stageBeginTime && record.stageEndTime ? `${record.stageBeginTime}-${record.stageEndTime}` : ''
        //   },
        // },

        // {
        //   title: '状态',
        //   dataIndex: 'frozenStatus',
        //   width: '80px',
        //   render: (text, record) => {
        //     return this.FROZEN_STATUS_ENUM[record.frozenStatus]
        //   },
        // },
        {
          title: '状态',
          key: 'frozenStatusTitle',
          dataIndex: 'frozenStatusTitle',
          align: 'center',
          children: [
            {
              title: '计划内',
              align: 'center',
              dataIndex: 'frozenStatus',
              key: 'frozenStatus',
              width: 90,
              render: (text, record) => {
                return this.FROZEN_STATUS_ENUM[record.frozenStatus]
              },
            },
            {
              title: '计划外',
              align: 'center',
              dataIndex: 'frozenStatusWay',
              key: 'frozenStatusWay',
              width: 90,
              render: (text, record) => {
                return this.FROZEN_STATUS_ENUM[record.frozenStatusWay]
              },
            },
          ],
        },
        {
          title: '操作',
          dataIndex: 'operate',
          width: '200px',
          fixed: 'right',
          render: columnRenders.operate(
            [
              { title: '增补', auth: quota_adjust_supply, 
                show: (text: any, record: any) => record['isHis'] !== 1,
                action: (text, record) => this.operationHand(record, 'add') 
              },
              {
                title: '扣减',
                auth: quota_adjust_deduct,
                show: (text: any, record: any) => record['isHis'] !== 1,
                action: (text, record) => this.operationHand(record, 'deduct'),
              },
              {
                title: '调剂',
                auth: quota_adjust_adjust,
                show: (text: any, record: any) => record['isHis'] !== 1,
                action: (text, record) => this.operationHand(record, 'adjust'),
              },
              {
                title: '客户间调整',
                auth: quota_adjust_adjustcustom,
                show: (text: any, record: any) => record['isHis'] !== 1,
                action: (text, record) => this.operationHand(record, 'customer'),
              },
            ],
            5
          ),
        },
      ],
      leftBtns: [
        uaaApp.canUse(quota_adjust_freezein) && <Button type="primary">冻结(0)</Button>,
        uaaApp.canUse(quota_adjust_unfreeze) && <Button type="primary">解冻(0)</Button>,
        uaaApp.canUse(quota_adjust_freezein_batch) && (
          <Button
            type="primary"
            onClick={() => {
              this.batchHandlerBatch(0)
            }}
          >
            批量冻结
          </Button>
        ),
        uaaApp.canUse(quota_adjust_export) && (
          <Button type="primary" onClick={this.handExportQuotaAdjust}>
            导出
          </Button>
        ),
        <Button type="primary" onClick={this.handImportCodeFileExcel}>
          导入编码搜索
        </Button>,
      ],
      rightBtns: [
        uaaApp.canUse(quota_adjust_log) && (
          <Button type="default" onClick={this.openAdjustRecord}>
            调整记录
          </Button>
        ),
        uaaApp.canUse(quota_adjust_freezelog) && (
          <Button type="default" onClick={this.openFreezeRecord}>
            冻结解冻记录
          </Button>
        ),
      ],
      tableProps: {
        scroll: { x: true },
        bordered: true,
        rowSelection: {
          onChange: this.onSelectChange,
        },
        footer: () => (
          <div>
            <span style={{ fontWeight: 'bold', fontSize: 14 }}>主要公式说明</span>
            <br />
            经销商计划（内、外）考核阶段实际配额：考核有效期内的实际配额 <br />
            经销商计划（内、外）已执行配额：考核有效期内实际配额已下单数 <br />
            经销商计划（内、外）考核阶段剩余配额=经销商计划（内、外）考核阶段实际配额-经销商计划（内、外）已执行配额
            <br />
            经销商计划（内、外）年度剩余配额=经销商计划（内、外）年度标准配额-经销商计划内年度实际配额
            <br />
          </div>
        ),
      },
      uploading: false,
      downloading: false,
      treeDataList: [],
      prodBarCodeList: [],
    }
  }
  componentWillUnmount() {
    this.setState = (state, callback) => {
      return
    }
  }
  componentDidMount() {
    super.componentDidMount()
    this.changeBrandCode(this.filterForm.getFieldValue('brandCode'))
  }

  private handGolinkOrder = (record: object, type: number): void => {
    UdDrawer.open({
      title: '关联订单',
      width: '50%',
      content: <LinkDetail record={record} type={type} />,
      footer: null,
    })
  }

  //重写方法-为了覆盖父类搜索-搜索后刷新解冻冻结数量
  protected handleSearch = (values: any) => {
    let p: Partial<IListQueryParams> = {
      conditions: values,
      v: new Date().getTime(),
    }
    if (this.state.pagination) {
      p.page = 1
    }
    this.handleParamsChange<IListQueryParams>(p)
    this.setState({
      leftBtns: [
        uaaApp.canUse(quota_adjust_freezein) && <Button type="primary">冻结(0)</Button>,
        uaaApp.canUse(quota_adjust_unfreeze) && <Button type="primary">解冻(0)</Button>,
        uaaApp.canUse(quota_adjust_export) && (
          <Button type="primary" onClick={this.handExportQuotaAdjust}>
            导出
          </Button>
        ),
        <Button type="primary" onClick={this.handImportCodeFileExcel}>
          导入编码搜索
        </Button>,
        uaaApp.canUse(quota_adjust_freezein_batch) && (
          <Button
            type="primary"
            onClick={() => {
              this.batchHandlerBatch(0)
            }}
          >
            批量冻结
          </Button>
        ),
      ],
    })
  }

  protected filterReset = (form: WrappedFormUtils) => {
    let defaultValues: any = {}
    _.forEach(this.state.conditions, (item: IUdFormItem) => {
      if (item.initialValue) {
        let key = _.isArray(item.id) ? item.id.join('|') : item.id
        defaultValues[key] = item.initialValue
      }
    })
    var conditions = _.merge({}, this.defaultQueryParams.conditions, defaultValues)
    this.handleSearch(conditions)
    this.changeBrandCode(this.brandList[0].value)
  }

  render() {
    return (
      <Spin
        spinning={this.state.uploading || this.state.downloading}
        tip={this.state.uploading ? '上传中，请稍后...' : '请求中，请稍后...'}
      >
        {super.render()}
      </Spin>
    )
  }

  private handExportQuotaAdjust = () => {
    this.setState({ downloading: true })
    let { brandCode } = this.filterForm.getFieldsValue()
    let brandName = this.brandList.find(item => {
      return item.value === brandCode
    })?.title
    http
      .post(quotaApis.exportQuotaAdjust, { ...this.queryParams.conditions }, { responseType: 'arraybuffer' })
      .then(res => {
        if (!res.data.code) {
          downBlobFileXlsx(res.data, `${brandName}-配额调整表格`)
        }
      })
      .finally(() => {
        this.setState({ downloading: false })
      })
  }

  private changeBrandCode = (value: any): void => {
    this.filterForm.setFieldsValue({ prodBarcode: undefined, belongAreaCode: undefined }, () => {
      this.setState({ prodBarCodeList: [], treeDataList: [] }, () => {
        Promise.allSettled([this.getProdBarList(value), this.getAreaList(value)]).then((res: any) => {
          this.setState({
            prodBarCodeList: res[0]?.value || [],
            treeDataList: res[1]?.value || [],
          })
        })
      })
    })
  }
  private getAreaList = (value: any) => {
    return http
      .get(apis.getTreeByUser, {
        params: { organizationCode: value },
      })
      .then(res => {
        let data = res?.data?.children || []
        return data
      })
  }

  private getProdBarList = (value: any): Promise<any> => {
    return http
      .get(quotaApis.getProdBarList, {
        params: { brandCode: value },
      })
      .then(res => {
        const { data = [] } = res
        const prodBarCodeList = data.map(item => ({ value: item.code, title: item.name }))
        return prodBarCodeList
      })
  }

  private mapTree = (data: any[]) => {
    return data.map(item => {
      return (
        <TreeNode value={item.code} title={item.name} key={item.code}>
          {this.mapTree(item?.children || [])}
        </TreeNode>
      )
    })
  }

  private onSelectChange = (selectedRowKeys: any[], selectedRows) => {
    let tableProps = this.state.tableProps
    if (tableProps && tableProps.rowSelection) {
      tableProps.rowSelection.selectedRowKeys = selectedRowKeys
    }

    let freezeCount = selectedRows.reduce((total, item) => {
      let count = 0
      if (item.idWay && item.frozenStatusWay === 0) count++
      if (item.id && item.frozenStatus === 0) count++
      return total + count
    }, 0)

    let unFreezeCount = selectedRows.reduce((total, item) => {
      let count = 0
      if (item.idWay && item.frozenStatusWay === 1) count++
      if (item.id && item.frozenStatus === 1) count++
      return total + count
    }, 0)

    this.setState({
      leftBtns: [
        uaaApp.canUse(quota_adjust_freezein) && (
          <Button
            type="primary"
            onClick={
              freezeCount
                ? () => {
                    this.batchHandler(0)
                  }
                : void 0
            }
          >
            冻结({freezeCount})
          </Button>
        ),
        uaaApp.canUse(quota_adjust_unfreeze) && (
          <Button
            type="primary"
            onClick={
              unFreezeCount
                ? () => {
                    this.batchHandler(1)
                  }
                : void 0
            }
          >
            解冻({unFreezeCount})
          </Button>
        ),
        uaaApp.canUse(quota_adjust_freezein_batch) && (
          <Button
            type="primary"
            onClick={() => {
              this.batchHandlerBatch(0)
            }}
          >
            批量冻结
          </Button>
        ),
        uaaApp.canUse(quota_adjust_export) && (
          <Button type="primary" onClick={this.handExportQuotaAdjust}>
            导出
          </Button>
        ),
        <Button type="primary" onClick={this.handImportCodeFileExcel}>
          导入编码搜索
        </Button>,
      ],
      selectedRowKeys,
      selectedRows,
      tableProps,
    })
  }

  private openAdjustRecord = (): void => {
    UdDrawer.open({
      title: '调整记录',
      content: <AdjustRecord brandList={this.brandList} />,
      width: '70%',
      footer: false,
    })
  }
  private openFreezeRecord = (): void => {
    UdDrawer.open({
      title: '冻结解冻记录',
      content: <FreezeRecord brandList={this.brandList} />,
      width: '80%',
      footer: false,
    })
  }

  private refresh = () => {
    this.handleSearch(this.filterForm.getFieldsValue())
  }

  private operationHand = (record: object, type: string): void => {
    let title = ''
    let contentComponent: ReactElement = <></>
    switch (type) {
      case 'add':
        title = '配额增补申请'
        contentComponent = <IncreaseForm record={record} handQuery={this.query} />
        break
      case 'deduct':
        title = '配额扣减申请'
        contentComponent = <DeductForm record={record} handQuery={this.query} />
        break
      case 'adjust':
        title = '调剂申请'
        contentComponent = <AdjustForm record={record} handQuery={this.query} />
        break
      default:
        title = '客户间调整申请'
        contentComponent = <CustomerForm record={record} handQuery={this.query} />
    }
    UdModal.open({
      title,
      content: (
        <UdModalForm
          items={[
            {
              id: 'planType',
              label: '计划类型',
              labelCol: { span: 9 },
              wrapperCol: { span: 15 },
              rules: [{ required: true, message: '请选择计划类型' }],
              render: (
                <Radio.Group>
                  <Radio value={0}>计划内</Radio>
                  <Radio value={1} disabled={!record['idWay']}>
                    计划外
                  </Radio>
                </Radio.Group>
              ),
            },
          ]}
        />
      ),
      okText: '确定',
      cancelText: '取消',
      onOk: values => {
        const { planType } = values
        UdDrawer.open({
          title,
          width: '50%',
          content: React.cloneElement(contentComponent, {
            planType,
            id: planType === 0 ? record['id'] : record['idWay'],
          }),
        })
      },
    })
  }

  public customerHandler = record => {
    UdDrawer.open({
      title: '客户间调整申请',
      width: '50%',
      content: <CustomerForm record={record} />,
    })
  }

  public batchHandlerBatch = (type: number): void => {
    let title = type === 0 ? '批量冻结' : '批量解冻'
    UdModal.open({
      title,
      content: (
        <UdModalForm
          items={[
            {
              id: 'planType',
              label: '计划类型',
              labelCol: { span: 9 },
              wrapperCol: { span: 15 },
              rules: [{ required: true, message: '请选择计划类型' }],
              render: (
                <Radio.Group>
                  <Radio value={0}>计划内</Radio>
                  <Radio value={1}>计划外</Radio>
                </Radio.Group>
              ),
            },
          ]}
        />
      ),
      okText: '确定',
      cancelText: '取消',
      onOk: values => {
        const { planType } = values
        UdDrawer.open({
          title,
          width: '70%',
          content: <BatchOperate planType={planType} frozenStatus={type} refresh={this.refresh} />,
        })
      },
    })
  }

  private handImportCodeFileExcel = () => {
    //客户编码模板导入
    this.modal = UdModal.open({
      title: '导入客户编码',
      width: 300,
      content: (
        <>
          <div style={{ display: 'flex', justifyContent: 'space-between' }}>
            <Button type="primary" onClick={this.handDownloadTemplate}>
              下载模板
            </Button>
            <Upload showUploadList={false} customRequest={this.handImportTemplate}>
              <Button type="primary">导入编码</Button>
            </Upload>
          </div>
        </>
      ),
      footer: null,
      maskClosable: true,
      centered: true,
    })
  }

  //客户编码模板下载
  private handDownloadTemplate = () => {
    this.modal && this.modal.destroy()
    http
      .get(quotaApis.downloadQuotaAgentImportExcel, { responseType: 'arraybuffer' })
      .then(res => {
        if (!res.data.code) {
          downBlobFileXlsx(res.data, `配额调整-客户编码导入模板`)
        }
      })
      .catch(err => {
        console.log(err)
      })
  }

  //客户编码模板导入
  private handImportTemplate = option => {
    this.modal && this.modal.destroy()
    const { file } = option
    const formData = new FormData()
    formData.append('file', file)
    let { brandCode } = this.filterForm.getFieldsValue()
    if (!brandCode) {
      message.warn('请选择品牌公司')
      return
    }
    let params: any = { brandCode }
    formData.append('agentLetterReqVo', new Blob([JSON.stringify(params)], { type: 'application/json' }))
    return http.post(inputApis.agentletterLaunchImport, formData, { timeout: 1000 * 60 * 10 }).then(res => {
      const dataSource = res?.data ?? []
      if (dataSource.length > 0) {
        this.filterForm.setFieldsValue({ dealerCode: dataSource.map(e => e.agentCode).join(',') }, () => {
          this.refresh()
        })
      }
    })
  }

  public batchHandler = (type: number): void => {
    let { selectedRowKeys, selectedRows } = this.state
    let title = type === 0 ? '冻结' : '解冻'
    if (selectedRowKeys.length === 0) {
      message.warn('请选择数据')
      return
    }
    let itemInside = selectedRows.filter(item => item.frozenStatus === type && item.id) ?? []
    let itemOut = selectedRows.filter(item => item.frozenStatusWay === type && item.idWay) ?? []
    if(itemInside.filter(item => item.isHis === 1).length>0 || itemOut.filter(item => item.isHis === 1).length>0){
      message.warn('历史配额数据不能进行'+title)
      return;
    }
    UdModal.open({
      title,
      content: (
        <UdModalForm
          items={[
            {
              id: 'planType',
              label: '计划类型',
              labelCol: { span: 9 },
              wrapperCol: { span: 15 },
              rules: [{ required: true, message: '请选择计划类型' }],
              render: (
                <Radio.Group>
                  <Radio value={0} disabled={!itemInside.length}>
                    计划内({itemInside.length})
                  </Radio>
                  <Radio value={1} disabled={!itemOut.length}>
                    计划外({itemOut.length})
                  </Radio>
                </Radio.Group>
              ),
            },
          ]}
        />
      ),
      okText: '确定',
      cancelText: '取消',
      onOk: values => {
        const { planType } = values
        let dataSource = planType === 0 ? itemInside : itemOut
        UdDrawer.open({
          title,
          width: '50%',
          content: <BatchFreeze planType={planType} dataSource={dataSource} refresh={this.refresh} />,
        })
      },
    })
  }
}

export default List

interface QuotaListState extends IBaseListPageState {
  uploading: boolean
  downloading: boolean
  selectedRowKeys?: any
  treeDataList: any[]
  prodBarCodeList: any[]
}

interface QuotaListProps extends IBaseListPageProps {}
